<template>
	<div style="padding:0 40px 50px;">
		<div class="table-border" v-show='agentDialog'>
			<div class="table-head">{{$t('agent.agent')}}</div>
			  	<el-table :data="agentAuditDatas" style="width: 100%;" height=400>
				    <el-table-column type="index" fixed :label="$t('index.Number')" width="70"></el-table-column>
				    <el-table-column prop="name" :label="$t('search.AgentName1')" ></el-table-column>
				    <el-table-column prop="address" :label="$t('agent.Address')" ></el-table-column>
				    <el-table-column prop="parentName" :label="$t('trade.Agent')" ></el-table-column>
				    <el-table-column prop="checkType" :label="$t('mer.ApprovalItem')" :formatter="AgentState"></el-table-column>
				    <el-table-column :label="$t('index.Operation')" width="150">
					    <template scope="scope">
					        <el-button class="blue-btn mini-btn" size="small" @click="showAgentDetails(scope.row.id)">{{$t('button.Approval')}}</el-button>
					    </template>
				    </el-table-column>
			 	</el-table>
			<div class="pagination-container">
    			<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="searchAgentData.page" :page-sizes="[10,20,30,50]" :page-size="searchAgentData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="res.total"></el-pagination>
  			</div>
		</div>
		<auditDetails v-if='agentAuditDialog' @auditAgentChange='auditAgentFun' :distributorId="distributorId"></auditDetails>
	</div>
</template>

<script>
	import { agentAll,agentDetails,updateStateAgent } from 'api/audit/agentAudit/index';
	import { auditDetails } from 'views/z_auditManage/componenets'
	export default{
		name:'agentAudit',
		components: { auditDetails },
		data(){
			return{
				agentDialog:true,
				agentAuditDialog:false,
				distributorId:null,//传递给子组件的值  代理商ID id
				agentAuditDatas:[],//后台返回的待审核代理商数据
				res:[],//分页 数据总条数
				searchAgentData:{//查询参数
					page:1,
					pageSize:10,
//					state:1
				},
			}
		},
		created(){
			this.agentAuditList(this.searchAgentData);
		},
		methods:{
			AgentState(row){
				let checkType = row.checkType;
				if(checkType === '进件' ){
					return checkType = this.$t("mer.Registration");
				}else if(checkType === '修改信息' ){
					return checkType = this.$t("mer.Amendment");
				}
			},
			//获取待审核代理商列表
			agentAuditList(value){
				value.companyId = localStorage.getItem('companyId');
				value.distributorId = localStorage.getItem('distributorId');
				agentAll(value).then(res=>{
					// console.log(res);
					this.agentAuditDatas = res.value.list;
					this.res = res.value;
				})
			},
			//进入子组件 显示改子组件详情
			showAgentDetails(id){
				this.distributorId = id;
				this.agentDialog = false;
				this.agentAuditDialog = true;
			},
			//监听子组件事件
  			auditAgentFun(){
  				this.agentDialog = true;
  				this.agentAuditDialog = false;
  				this.agentAuditList(this.searchAgentData);
  			},
  			 //pageSize 改变时会触发
			handleSizeChange(val){
				this.searchAgentData.pageSize = val;
				this.agentAuditList(this.searchAgentData);
			},
			//currentPage 改变时会触发
			handleCurrentChange(val){
				this.searchAgentData.page = val;
				this.agentAuditList(this.searchAgentData);
			}
		}
	}
</script>

<style>
</style>